//
//  NYDetailContentView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYDetailContentView.h"

@interface NYDetailContentView ()

@property (nonatomic, strong) QMUIGhostButton *messageButton;
@end
@implementation NYDetailContentView
- (void)setPlayerView:(UIView *)playerView
{
    _playerView = playerView;
    [playerView removeFromSuperview];
    [self.playerContentView removeAllSubviews];
    [self.playerContentView addSubview:playerView];
    [playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.playerContentView);
    }];
}
- (void)setupTableView
{
    self.tableView.backgroundColor = UIColorForBackground;
    self.backgroundColor = UIColorForBackground;
    self.playerContentView = [[UIView alloc] init];
    self.playerContentView.backgroundColor = [UIColor colorWithRed:35.0/255.0 green:35.0/255.0 blue:35.0/255.0 alpha:1];
    [self addSubview:self.playerContentView];
    
    [self addSubview:self.messageButton];
    
    [self.playerContentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*))
        {
            make.top.equalTo(self.mas_safeAreaLayoutGuideTop);
            make.left.equalTo(self.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.mas_safeAreaLayoutGuideRight);
        }
        else
        {
            make.top.equalTo(self.controller.mas_topLayoutGuideBottom);
            make.left.right.equalTo(self);
        }
        make.height.equalTo(self.playerContentView.mas_width).multipliedBy(9.0/16.0);
    }];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.playerContentView.mas_bottom);
        if (@available(iOS 11.0,*))
        {
            make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom);
            make.left.equalTo(self.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.mas_safeAreaLayoutGuideRight);
        }
        else
        {
            make.bottom.equalTo(self.controller.mas_bottomLayoutGuideTop);
            
            make.left.right.equalTo(self);
        }
    }];
    
    [self.messageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        if (@available(iOS 11.0,*))
        {
            make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom).offset(-45);
        } else {
            make.bottom.equalTo(self).offset(-45);
        }
        make.right.mas_equalTo(-15);
        make.width.height.mas_equalTo(50.f);
    }];
    
    @weakify(self);
    [self.messageButton jk_addActionHandler:^(NSInteger tag) {
        
        @strongify(self);
        if (self.messageButtonHandle) self.messageButtonHandle();
    }];
}

- (QMUIGhostButton *)messageButton {
    if (!_messageButton) {
        _messageButton = [[QMUIGhostButton alloc] qmui_initWithImage:UIImageMake(@"jia_hao_xuan_fu") title:nil];
        _messageButton.backgroundColor = UIColorMakeWithHex(@"#5396FF");
        _messageButton.cornerRadius = 25.f;
        _messageButton.layer.shadowOffset = CGSizeMake(0, 3); //阴影的位置
        _messageButton.layer.shadowRadius = 3.0;//阴影的圆角
        _messageButton.layer.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.5].CGColor; //阴影的颜色
        _messageButton.layer.shadowOpacity = 0.8;//阴影的透明度
    }
    return _messageButton;
}
@end
